window.component2_edit_flag=true;
component2_props_add_data={
    var_name:"",//绑定的变量名 编辑状态下可能会使用的参数
    all_set_data:null,//所有的数据
    con2_father_this: null,
    con2_idx: "",
    deepcopy_data:null,//用于传递参数
};

log_flag=false
log_print=function(...args){
        if(log_flag==true){
            console.log(...args)
        }
    }
component2_data_add_data__={
    var_name:'',//用于设置组件的全局访问对象
    __test_flag:false,//组件用到的测试参数
    body_data:[],
    // ___name:name_,//组件名称
    __father_this:null,//作为属性容器下的子组件 可以通过此直接访问属性容器的this
    __child_idx:null,//作为 
    __only_id:"test",//项目中被渲染的组件id: 项目拥有者id_项目目录id_项目id_页面id_组件id
    __style:{
        __edit_flag__:true,//如果该组件处于编辑状态 是否启用var_name
        __height:"100%",//高度
        __width:"100%",//宽度
        __margin:"null",
        __margin_x:"null",
        __margin_y:"null",
        __margin_right:"0px",//
        __margin_left:"0px",//
        __margin_top:"0px",//
        __margin_bottom:"0px",//
        __padding:"null",
        __padding_x:"null",
        __padding_y:"null",
        __padding_left:"0px",//
        __padding_right:"0px",//
        __padding_top:"0px",//
        __padding_bottom:"0px",//
    }
}
component2_data_add_data=function(name_,data,new_component2_data_add_data__){
    let res=function(){
        let val_obj=data();
        new_component2_data_add_data__.___name=name_;//组件名称
        let res_val={data:JSON.parse(JSON.stringify(new_component2_data_add_data__))};
        // console.log("new_component2_data_add_data__",JSON.parse(JSON.stringify(new_component2_data_add_data__)))
        // console.log("val_obj",JSON.parse(JSON.stringify(val_obj)))
        lhp_deepcopy1(res_val,val_obj)
        return res_val
    }
    return res
}
component2_methods_add_data={
    get_ref:function(ref_name){
        try{
            let ref_obj=this.$refs[ref_name];
            if(Array.isArray(ref_obj)){ref_obj=ref_obj[0];}
            return ref_obj
        }catch{
        throw new Error(this,this.data.var_name,'不存在这个ref名称:',ref_name); 
        }
    },
    _log:function(...lst){if(this.data.__test_flag){console.log(...lst)}},
    ___set_width:function(name,e){this.$refs[name].width=e},
    ___set_height:function(name,e){this.$refs[name].height=e},
    ___set_padding_left:function(name,e){this.$refs[name].style['paddingLeft']=e},
    ___set_padding_right:function(name,e){this.$refs[name].style['paddingRight']=e},
    ___set_padding_top:function(name,e){this.$refs[name].width.style['paddingTop']=e},
    ___set_padding_bottom:function(name,e){this.$refs[name].style['paddingBottom']=e},
    ___set_margin_left:function(name,e){this.$refs[name].style['marginLeft']=e},
    ___set_margin_right:function(name,e){this.$refs[name].style['marginRight']=e},
    ___set_margin_top:function(name,e){this.$refs[name].style['marginTop']=e},
    ___set_margin_bottom:function(name,e){this.$refs[name].style['marginBottom']=e},
    //编辑状态下禁止启用循环功能
    lhp_start_loop_once:function(params){if(this.is_edit==true){
        log_print("编辑模式下 无限循环监听功能循环次数设置为100:",this.data.var_name);
        params.count_max=1000
        };
        log_print(this.data.var_name,"run lhp_start_loop_once",params);
        lhp_start_loop_once(params)
    },
    accumulateParentOffsets:function (targetElement) {  
        let currentElement = targetElement;  
        let totalLeft = 0;  
        let totalTop = 0;  
      
        while (currentElement && currentElement.nodeType === Node.ELEMENT_NODE) {  
            let computedStyle = window.getComputedStyle(currentElement);  
              
            if (computedStyle.position === 'relative') {  
                // 注意：offsetLeft 和 offsetTop 给出的是相对于最近的定位祖先的偏移  
                // 在这里，我们假设没有其他的定位祖先（或它们不影响我们的计算）  
                // 因为我们只关心 relative 定位的父元素  
                totalLeft += currentElement.offsetLeft;  
                totalTop += currentElement.offsetTop;  
            }  
      
            currentElement = currentElement.parentElement;  
        }  
      
        return { left: totalLeft, top: totalTop };  
    },
    get_x_y:function(event,ref_name){
    let x=event.clientX;
    let y=event.clientY;
    let res=this.accumulateParentOffsets(this.$refs[ref_name]);//累加所有relative 父dom的left和top
    return {x:res.left+x,y:res.top+y};
    },
    get_x_y2:function(event,ref_name){
    let x=event.clientX;
    let y=event.clientY;
    let res=this.accumulateParentOffsets(this.$refs[ref_name]);//累加所有relative 父dom的left和top
    return {x:x-res.left,y:y-res.top};
    },
    get_xys:function (targetElement) {  
        let currentElement = targetElement;  
        let totalLeft = 0;  
        let totalTop = 0;  
      
        while (currentElement && currentElement.nodeType === Node.ELEMENT_NODE) {  
            let computedStyle = window.getComputedStyle(currentElement);  
              
            if (computedStyle.position === 'relative') {  
                // 注意：offsetLeft 和 offsetTop 给出的是相对于最近的定位祖先的偏移  
                // 在这里，我们假设没有其他的定位祖先（或它们不影响我们的计算）  
                // 因为我们只关心 relative 定位的父元素  
                totalLeft += currentElement.offsetLeft;  
                totalTop += currentElement.offsetTop;  
            }  
      
            currentElement = currentElement.parentElement;  
        }  
        let rect = targetElement.getBoundingClientRect();
    
        let width = rect.width;
        
        let height = rect.height;
        return { left: totalLeft, top: totalTop,width:width,height:height};  
    },
    init_con2:function(){
        let _this=this;
        // 将con2 容器的子组件 在初始化的时候将this传递给con2容器 start
        if(_this.con2_idx!='null'){
        try{
            // console.log("_this.con2_father_this",_this.con2_father_this)
        if(!_this.con2_father_this.fast_child){_this.con2_father_this.fast_child={}}
        let f=_this.con2_father_this.fast_child;
        if(!f[_this.con2_idx]){f[_this.con2_idx]={}}
        let f_lst=_this.deepcopy_data.__only_id.split("_");
        f[_this.con2_idx][f_lst[f_lst.length-1]]=_this;

        }catch{}
        // 将con2 容器的子组件 在初始化的时候传递给con2容器   end
    }
}
};
component2_watch_add_data={
'data.var_name':function(e){
    if(this.is_edit &&this.__edit_flag__==false){return;}
    lhp_check_obj(window,e,this.data);log_print(e,"已装载:",window[e])
    log_print("this.data.varname=",e)
    window[e+"_____x"]=this;

},
'data.body_data':{
handler(e, oldVal) {
    // console.log("e",e)
    let _this=this;
    try{
        if(!this.__body_data_md5){this.__body_data_md5={}}
            let l=e.length;
            let new_d=[];
            for(let i=0;i<l;i++){new_d.push(null)}
            let vue_obj=_this.tbody_obj.$refs.ref_obj;
            _this.tbody_obj.$refs.ref_obj.data.data=new_d;
            vue_obj.$nextTick(()=>{
            let new_dct={};
            for(let i=0;i<l;i++){
                let old_md5=_this.__body_data_md5[i];
                let new_md5=md5(JSON.stringify(e[i]));
                if(new_md5!=old_md5){
                    let body_keys=Object.keys(_this.data.__father_data);
                    let new_keys={};
                    for (let i=0;i<body_keys.length;i++){
                      let k_lst=body_keys[i].split("_");
                      new_keys[k_lst[k_lst.length-1]]=body_keys[i];
                    }
                    try{
                      let data=_this.data.body_data[i];
                    //   console.log("开始同步第",i,"条数据",new_keys,data);
                      for(let key in new_keys){
                        // console.log("lhp_deepcopy1(this.fast_child[i][key].data,data[new_keys[key]])",this.fast_child[i][key].data,data,key,data[12],data[new_keys[key]])
                        try{lhp_deepcopy1(_this.fast_child[i][key].data,data[key]);}catch (err){}
                        
                      }
                }catch{}
                new_dct[i]=new_md5;

            }
        }});

    }catch{}
},
deep: true, // 启用深度监听
immediate: false // 设置为 true 会在绑定时立即执行一次 handler
}
}
component2_mounted_start_data=`
let _this=this;
try{_this.data.return_this=function(){return _this}}catch{}
try{_this.data.__name=_this.$options.__name;}catch{}
try{_this.data._use_type=_this.$options._use_type;}catch{}

`

component2_created_start_data=`
let _this=this;
try{_this.init_con2();}catch{}
`
component2_created_end_data=``
component2_mounted_end_data=`
if (_this.var_name){
    _this.data.var_name=_this.var_name;
    window[_this.var_name]=_this.data;
    window[_this.var_name+"_____x"]=_this;

}


if(_this.deepcopy_data&&(window.component2_edit_flag==false)){lhp_deepcopy1(_this.deepcopy_data,{__style:{__edit_flag__:false} })}
try{if (_this.deepcopy_data){lhp_deepcopy1(_this.data,_this.deepcopy_data);}}//读取编辑状态下设定的参数
catch(error){log_print("######################",_this.deepcopy_data.var_name,"渲染出错:",error)}

`
component2_test_flag=false;
Vue.component2=function(temp_template_name,obj){
    let new_component2_data_add_data__=JSON.parse(JSON.stringify(component2_data_add_data__));
    let new_component2_props_add_data=JSON.parse(JSON.stringify(component2_props_add_data));
    let new_component2_methods_add_data={};lhp_deepcopy1(new_component2_methods_add_data,component2_methods_add_data);
    let new_component2_watch_add_data={};lhp_deepcopy1(new_component2_watch_add_data,component2_watch_add_data);
    if(component2_test_flag){log_print("加载模板:",temp_template_name)}
    //自定义属性初始化
    if (!obj.hasOwnProperty("watch_bind")){obj["watch_bind"] = {};}//监听后 将值绑定为方法名=>data.方法名  方法绑定对应函数
    if (!obj.hasOwnProperty("watch_init")){obj["watch_init"] = {};}//监听后 将值作为传参运行 对应函数
    if (!obj.hasOwnProperty("watch_regist")){obj["watch_regist"] = {};}//监听后 将值作为函数运行 用于注册配置相关信息
    if (!obj.hasOwnProperty("recv_callback_func")){obj["recv_callback_func"] = {};}//接收回调函数的 函数    '___xxx":function(calback_func){this.data.___xxxxx.push(callback_func)}
    if (!obj.hasOwnProperty("bind_recv_callback_func")){obj["bind_recv_callback_func"] = {};}//绑定 接收回调函数的 函数  '___ccc'
    if(component2_test_flag){log_print("自定义属性初始化 完成")}
    //默认属性初始化
    if (!obj.hasOwnProperty("props")){obj["props"] = {};} 
    if (!obj.hasOwnProperty("data")){obj["data"] = function(){return {}};} 
    if (!obj.hasOwnProperty("methods")){obj["methods"] = {};} 
    if (!obj.hasOwnProperty("watch")){obj["watch"] = {};} 
    if (!obj.hasOwnProperty("mounted")){obj["mounted"] = function(){};} 
    if (!obj.hasOwnProperty("created")){obj["created"] = function(){};} 
    if(component2_test_flag){log_print("默认属性初始化 完成")}
    //获取并删除自定义参数
    let watch_bind=obj.watch_bind;delete obj.watch_bind;  
    let watch_init=obj.watch_init;delete obj.watch_init;
    let watch_regist=obj.watch_regist;delete obj.watch_regist;
    let recv_callback_func=obj.recv_callback_func;delete obj.recv_callback_func;  
    let bind_recv_callback_func=obj.bind_recv_callback_func;delete obj.bind_recv_callback_func;  
    if(component2_test_flag){log_print("获取并删除自定义参数 完成")}
    //自定义属性初始处理
    //----------------------watch_bind
    for(let key in watch_bind){
        //设置data初始值为''
        new_component2_data_add_data__[key]="";
        //设置method
        let md_name=key+"_____bn";
        new_component2_methods_add_data[md_name]=watch_bind[key];
        //设置watch监听
        new_component2_watch_add_data['data.'+key]=function(e){log_print("eeeeeee",e);lhp_check_obj(this.data,e,this[md_name])}
    }
    //----------------------watch_init
    for(let key in watch_init){
        //设置data初始值为''
        new_component2_data_add_data__[key]="";
        //设置watch监听
        new_component2_watch_add_data['data.'+key]=watch_init[key];
    }
    //----------------------watch_regist
    for(let key in watch_regist){
        let watch_regist_obj=watch_regist[key];
        // log_print(this.data.var_name,'watch_regist_obj',watch_regist_obj)
        let regist_path=watch_regist_obj.regist_path;//注册路径
        let try_type=watch_regist_obj.type;//报错不删除对象
        let callback_name=watch_regist_obj.callback_name;//注册后获取到的注册对象
        let recv_data_name=watch_regist_obj.recv_data_name;//接收数据的属性名称  this.data[recv_data_name]
        let recv_func_check_ref=watch_regist_obj.recv_func_check_ref;//不为空 则会检查ref是否存在才会运行后续函数
        let recv_func=watch_regist_obj.recv_func;//后续函数
        let other_callback=watch_regist_obj.other_callback;
        let new_other_callback={};
        //后续函数绑定到 methods中
        if (recv_func!=null && recv_func!=undefined){new_component2_methods_add_data[key+'___recv_func']=recv_func;}
        
        let new_func=function(e){
            let _this=this;
            let watch_regist_set_this=_this;
            if((watch_regist_set_this['watch_regist_set_'+key+'_flag']!=true)&&(!(other_callback===undefined))){
                watch_regist_set_this['watch_regist_set_'+key+'_flag']=true;
                for(let key33 in other_callback){
                    watch_regist_set_this['watch_regist_set_'+key+'_bind_other_callback_'+key33]=other_callback[key33]
                    
                new_other_callback[key33]=function(...params){
                    watch_regist_set_this['watch_regist_set_'+key+'_bind_other_callback_'+key33](...params);
                }
                }
            }

            _this.lhp_start_loop_once({
                func:e,//注册函数 xxx.xxx
                params:{//注册参数
                    _this:_this,
                    other_callback:new_other_callback,//监听的其他数据
                    var_name:_this.data.var_name,
                    path:regist_path,//注册绑定的路径
                    type:try_type,//报错不删除对象
                    func:function(obj){
                        _this.data.test_flag=true;
                        try{if(_this.data.test_flag==true){log_print("【",_this.data.var_name,"】","传参数据2:",obj)}}catch{}
                        log_print("【",_this.data.var_name,"】","调用回调函数")
                        let path=obj.path;//更新数据的路径
                        let data_type=obj.data_type;
                        let data=obj.data
                        if(path==''){path=recv_data_name}else{path=recv_data_name+'.'+path}
                        try{if(_this.data.test_flag==true){log_print("【",_this.data.var_name,"】","更新数据和路径:",path,data)}}catch{}
                        //更新数据
                        try{
                            lhp_vue_set({data_type:data_type,_this:_this,path:path,data:data,before_idx:obj.before_idx});
                            try{if(_this.data.test_flag==true){log_print('更新完毕:',_this)}}catch{}
                            if (recv_func_check_ref!=''&&recv_func_check_ref!=null &&recv_func_check_ref!=undefined){
                                ttime3(recv_func_check_ref,_this[key+'___recv_func'])
                            }else if(recv_func!=null && recv_func!=undefined){
                                
          log_print("xczxczx start ---1")
                                _this[key+'___recv_func']()
                            
          log_print("xczxczx start ---2")}
                        }catch(error) {  
                            // 如果try块中的代码抛出了错误，控制将跳转到这里  
                            // error对象包含了错误的详细信息  
                            log_print("【",_this.data.var_name,"】","捕获到错误:", error.message); // 使用
                        }
                    },//数据更新后同步执行的函数
            },
                callback:function(get_data_func){//回调函数
                //主动获取注册路径的数据   get_data_func(now_data) 通过判断now_data的md5与配置对象当前存储的数据 来选择是否进行数据更新
                _this.data[callback_name]=get_data_func;
            }
            });

        }
        //设置data初始值为''
        new_component2_data_add_data__[key]="";
        //设置watch监听
        new_component2_watch_add_data['data.'+key]=new_func;
    }
    if(component2_test_flag){log_print("自定义属性初始处理 完成")}
    
    //----------------------recv_callback_func
    
    for(let key in recv_callback_func){
        //设置data初始值为''
        new_component2_data_add_data__[key]="";
        //设置method
        let md_name=key+"_____bn";
        new_component2_methods_add_data[md_name]=recv_callback_func[key];
        //设置watch监听
        new_component2_watch_add_data['data.'+key]=function(e){lhp_check_obj(this.data,e,this[md_name])}
    }
    //----------------------bind_recv_callback_func
    log_print(temp_template_name,"bind_recv_callback_func",bind_recv_callback_func)
    for(let key in bind_recv_callback_func){
        //设置data初始值为''
        new_component2_data_add_data__[key]="";
        //设置watch监听
        new_component2_watch_add_data['data.'+key]=bind_recv_callback_func[key];
    }
    //默认属性初始处理
    //----------------------props
    lhp_deepcopy1(obj['props'],new_component2_props_add_data)
    //----------------------data
    obj.data=component2_data_add_data(temp_template_name,obj.data,new_component2_data_add_data__);
    //----------------------methods
    lhp_deepcopy1(obj['methods'],new_component2_methods_add_data)
    //----------------------watch
    lhp_deepcopy1(obj['watch'],new_component2_watch_add_data)
    //----------------------mounted
    let mounted_str=null,start=null,end=null;
    mounted_str=obj['mounted'].toString();
    start=mounted_str.indexOf('{'),end=mounted_str.lastIndexOf('}'); 
    mounted_str=mounted_str.slice(start + 1, end);
    window.last_dom={
        component2_mounted_start_data:component2_mounted_start_data,
        mounted_str:mounted_str,
        component2_mounted_end_data:component2_mounted_end_data,

    }
    // console.log("1")
    // console.log(component2_mounted_start_data,mounted_str,component2_mounted_end_data)
    obj['mounted']=new Function(component2_mounted_start_data+'\n'+mounted_str+'\n'+component2_mounted_end_data);
    
    let created_str=null;
    created_str=obj['created'].toString();
    start=created_str.indexOf('{'),end=created_str.lastIndexOf('}'); 
    created_str=created_str.slice(start + 1, end);
    obj['created']=new Function(component2_created_start_data+'\n'+created_str+'\n'+component2_created_end_data);
    // console.log("2")
    if(component2_test_flag){log_print("默认属性初始处理 完成")}
    //----------------------其他
    obj._name=temp_template_name;//设置name
    obj.name=vue_temp_change_name(temp_template_name);//设置name
    if(component2_test_flag){log_print("其他处理 完成")}
    if(component2_test_flag){log_print("开始调用vue函数定义全局组件")}
    //调用vue函数定义全局组件
    // console.log(temp_template_name,obj.created)
    Vue.component(temp_template_name,obj);
}